//
//  BCChartView.m
//  BangcaiSale
//
//  Created by lsy on 16/7/8.
//  Copyright © 2016年 Bangcai. All rights reserved.
//

#import "BCChartView.h"
#import "BCDataview.h"
@interface BCChartView ()
{
    UIScrollView *backScroll;
    UILabel *titleLab;
    UILabel *footLab;
    
}

@end

@implementation BCChartView

- (void)createView
{
    backScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH , 230 *hx)];
    [self addSubview:backScroll];
    backScroll.contentSize = CGSizeMake(3 * SCREEN_WIDTH, 0);
    backScroll.pagingEnabled = YES;
    backScroll.showsHorizontalScrollIndicator = NO;
    
    NSArray *arr1 =@[@15,@46,@30,@70,@50,@13,@85];
    NSArray *arr2 =@[@90,@10,@150,@20,@70,@113,@75];
    NSArray *arr3 =@[@10,@80,@130,@40,@10,@96,@20];
    NSArray *arr = @[arr1, arr2, arr3];
    
    NSMutableArray *date = [NSMutableArray arrayWithCapacity:3];
    NSInteger currentWeekDay = [BCDateTool weekDay:[NSDate date]];
    NSDate *currentWeekStart = [BCDateTool GetDayWithIndex:(1-currentWeekDay) From:[NSDate date]];
    NSDate *currentweekEnd = [BCDateTool GetDayWithIndex:(7-currentWeekDay) From:[NSDate date]];
    for (int index=0; index<3; index++) {
        NSDate *weekStart = [BCDateTool GetDayWithIndex:((-7)*index) From:currentWeekStart];
        NSDate *weekEnd = [BCDateTool GetDayWithIndex:((-7)*index) From:currentweekEnd];
        NSString *weekDuringString = [NSString stringWithFormat:@"%@-%@",
                                 [BCDateTool dateStringFromDate:weekStart],
                                 [BCDateTool dateStringFromDate:weekEnd]];
        [date insertObject:weekDuringString atIndex:0];
    }
    
    for (NSInteger i = 0; i < 3; i++) {
        BCDataview *dataView = [[BCDataview alloc] initWithFrame:CGRectMake( i *SCREEN_WIDTH, 0, SCREEN_WIDTH, 200 *hx)];
        dataView.dataArr = arr[i];
        dataView.date = date[i];
        UIButton *nextPage = [UIButton buttonWithType:UIButtonTypeCustom];
        UIButton *lastPage = [UIButton buttonWithType:UIButtonTypeCustom];
        [nextPage setImage:[UIImage imageNamed:@"下一步-灰"] forState:UIControlStateNormal];
        [lastPage setImage:[UIImage imageNamed:@"左-灰"] forState:UIControlStateNormal];
        
        [dataView addSubview:nextPage];
        [dataView addSubview:lastPage];
        
        [nextPage addTarget:self action:@selector(nextPage) forControlEvents:UIControlEventTouchUpInside];
        [lastPage addTarget:self action:@selector(lastPage) forControlEvents:UIControlEventTouchUpInside];
        
        
        [nextPage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(14);
            make.height.mas_equalTo(20);
            make.right.mas_equalTo(-12);
            make.centerY.mas_equalTo(0);
            
        }];
        
        [lastPage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(14);
            make.height.mas_equalTo(20);
            make.left.mas_equalTo(12);
            make.centerY.mas_equalTo(0);
        }];
        if (i == 0) {
            lastPage.hidden = YES;
        }else if (i == 2){
            nextPage.hidden = YES;
        }
        
        [backScroll addSubview:dataView];
        
    }
    backScroll.contentOffset = CGPointMake(2 *SCREEN_WIDTH, 0);

    [self getData];
    
}

- (void)nextPage{
    backScroll.contentOffset = CGPointMake(backScroll.contentOffset.x +SCREEN_WIDTH, 0);
}

- (void)lastPage{
    backScroll.contentOffset = CGPointMake(backScroll.contentOffset.x -SCREEN_WIDTH, 0);

}

- (void)getData{
    
}

@end
